package com.zlf.controller;

import com.zlf.po.CommonResult;
import com.zlf.po.Remark;
import com.zlf.service.RemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.util.List;
@RestController
@RefreshScope  //开启动态刷新
@RequestMapping("/RemarkController")
public class RemarkController {

    @Autowired
    private RemarkService remarkService;

    @PostMapping("/saveRemarks/{userId}/{userName}/{businessId}/{remark}")
    public CommonResult saveRemarks(@PathVariable("userId") String userId,
                                    @PathVariable("userName") String userName,
                                    @PathVariable("businessId") int businessId,
                                    @PathVariable("remark") String remark
    ){
        Remark pram=new Remark();
        pram.setUserId(userId);
        pram.setUserName(userName);
        pram.setBusinessId(businessId);
        pram.setRemark(remark);
        int res=remarkService.saveRemarks(pram);
        return new CommonResult(200,"success",res);
    }
    @PostMapping("/deleteRemarks/{remarkId}")
    public CommonResult deleteRemarks(@PathVariable("remarkId") int remarkId) {
        int res= remarkService.deleteRemark(remarkId);
        return new CommonResult(200,"success",res);
    }
    @GetMapping("/listRemarksByBussinessId/{businessId}")
    public CommonResult listRemarksByBussinessId(@PathVariable("businessId")int businessId) throws Exception{
        List<Remark>res= remarkService.listRemarksByBussinessId(businessId);
        return new CommonResult(200,"success",res);
    }

}
